package com.innodealing.consumer;

import com.innodealing.hermes.kafka.annotation.HermesKafkaListener;
import com.innodealing.hermes.kafka.listener.HermesBatchOrderlyListener;
import com.innodealing.hermes.kafka.model.KafkaMessage;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
@HermesKafkaListener(topics = "hermes_example", groupId = "hermes-example-group")
public class HermesKafkaListenerExample implements HermesBatchOrderlyListener {
    @Override
    public void onMessage(List<KafkaMessage> kafkaMessages) {
        for (KafkaMessage kafkaMessage : kafkaMessages) {
            String value = kafkaMessage.getContent();
            try {
                // 模拟业务处理逻辑
                if (value.contains("error")) {
                    throw new RuntimeException("业务处理异常: " + value);
                }
                System.out.println("处理成功: " + value);
            } catch (Exception e) {
                System.err.println("消息处理失败: " + value + ", 错误: " + e.getMessage());
                throw e;
            }
        }
    }
}
